home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d21
/
dvglue.arc
/
TVJNEW.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-09
|
5KB
|
168 lines
/*=======================================================*/
/* TVJNEW.C */
/* */
/* (c) Copyright 1988 Ralf Brown All Rights Reserved */
/* May be freely copied for noncommercial use, so long */
/* as this copyright notice remains intact, and any */
/* changes are marked in the comment blocks preceding */
/* functions. */
/*=======================================================*/
#include <string.h>
#include <stdarg.h>
#include "tvapi.h"
#define STACKSIZE 256
OBJECT _TV_newapp_mutex_ = NULL ;
/*======================================================*/
struct EXEC_block {
int env ; /* segment of environment */
char far *cmdline ;
char far *fcb_1 ;
char far *fcb_2 ;
} ;
static char *new_program ;
static struct EXEC_block *exec_block ;
/*======================================================*/
/* launch_app fork to here, and then EXEC the program */
/* Ralf Brown 5/10/88 */
/* Ralf Brown 6/6/88 added own spawn routine */
/*======================================================*/
static void launch_app(int parent)
{
struct EXEC_block *exec_blk = exec_block ;
char *program = new_program ;
union REGS regs ;
struct SREGS sregs ;
(void) parent ; /* satisfy TurboC's warnings about unused parameters */
/* we've now got copies of the static variables, so we can unblock */
TVunlock(_TV_newapp_mutex_) ;
TVwin_swrite(NIL,"Loading...\r\n") ;
/* EXEC the program and get its exit code */
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
sregs.ds = _DS ;
regs.x.dx = (int) program ;
sregs.es = _DS ;
regs.x.bx = (int) exec_blk ;
#else
sregs.ds = FP_SEG( program ) ;
regs.x.dx = FP_OFF( program ) ;
sregs.es = FP_SEG( exec_blk ) ;
regs.x.bx = FP_OFF( exec_blk ) ;
#endif
regs.x.ax = 0x4B00 ; /* EXEC with load&run option */
intdosx( ®s, ®s, &sregs ) ;
#if 0 /* waiting for completion code hangs process */
if ((regs.x.cflag & 1) == 0)
{
regs.h.ah = 0x4D ; /* if load was successful, wait for completion */
intdos( ®s, ®s ) ;
}
#endif 0
free(program) ;
free((char *) exec_blk->fcb_1) ;
free((char *) exec_blk->cmdline) ;
free(exec_blk) ;
}
/*======================================================*/
/* TVapp_new create new application in current process */
/* Ralf Brown 5/10/88 */
/*======================================================*/
OBJECT cdecl TVapp_new(OBJECT win,int row,int col,int rows,int cols,char *program, ...)
{
OBJECT new_app = NIL ;
va_list args ;
char *arg ;
int cmd_len = 0 ;
char *cmd_line, *cmd, *rest ;
struct fcb *fcb1, *fcb2 ;
/* allocate space for the commandline and FCBs */
if ((cmd_line = malloc(128)) != NULL)
cmd = cmd_line+1 ;
else
goto error2 ;
if ((fcb1 = malloc(2*sizeof(struct fcb))) != NULL)
fcb2 = fcb1+1 ;
else
{
free(cmd_line) ;
goto error2 ;
}
/* we'll be overwriting static vars, so can only have one copy here at a time */
if (!TVisobj(_TV_newapp_mutex_))
_TV_newapp_mutex_ = TVmbx_new() ;
TVlock(_TV_newapp_mutex_) ;
if ((new_program = (char *)malloc(strlen(program)+1)) != NULL)
strcpy(new_program, program) ;
else
{
free(cmd_line) ;
free(fcb1) ;
goto error ;
}
if ((exec_block = malloc(sizeof(struct EXEC_block))) != NULL)
{
exec_block->env = 0 ;
exec_block->cmdline = (char far *)cmd_line ;
exec_block->fcb_1 = (char far *)fcb1 ;
exec_block->fcb_2 = (char far *)fcb2 ;
}
else
{
free(cmd_line) ;
free(fcb1) ;
free(new_program) ;
goto error ;
}
/* then concatenate the args to form the commandline */
va_start(args, program) ;
(void) va_arg( args, char * ) ; /* skip argv[0] */
while ((arg = va_arg(args, char *)) != NULL)
{
while (*arg && cmd_len < 126)
{
*cmd++ = *arg++ ;
cmd_len++ ;
}
if (cmd_len >= 126)
{
cmd_len = 126 ;
break ;
}
else
{
*cmd++ = ' ' ; /* separate args by blanks */
cmd_len++ ;
}
}
cmd_line[0] = cmd_len ;
cmd_line[cmd_len+1] = '\r' ;
va_end( args ) ;
/* now set up the FCBs */
rest = parsfnm( cmd_line+1, (struct fcb *)fcb1, 1 ) ; /* 1=ignore leading separators */
if (rest) /* was first parse successful? */
rest = parsfnm( rest, (struct fcb *)fcb2, 1 ) ;
/* and launch the program */
new_app = TVnew_task(win,NULL,row,col,rows,cols,NULL,STACKSIZE,launch_app) ;
if (new_app)
TVlock(_TV_newapp_mutex_) ; /* wait until launch_app() releases exclusion */
else
return NIL ;
error:
TVunlock(_TV_newapp_mutex_) ;
error2:
return new_app ;
}
/* End of TVJNEW.C */